<%= turbo_frame_tag 'report' do %>
  <div class="flex mt-8 flex-col lg:flex-row gap-4">
    <div class="flex flex-col rounded-box gap-2 bg-base-100 p-4 lg:w-1/5 border border-base-300">
      <h4 class="text-xs text-base-content uppercase">
        <%= t(".total") %>
      </h4>
      <span class="text-xl font-medium text-base-content">
        <%= @total_in_hours %> <%= t("hours").downcase %>
      </span>
    </div>
  </div>

  <div class="mt-8 overflow-x-auto">
    <% if @time_entries.any? %>
      <div class="card bg-base-100 rounded-box border border-base-300">
        <div class="card-body">
          <table class="table table-md table-zebra table-pin-rows table-pin-cols">
            <thead>
              <tr>
                <th style="width: 30px;" class="text-center">#</th>
                <th><%= t(".date") %></th>
                <th><%= Project.model_name.human %></th>
                <th><%= TimeEntry.human_attribute_name(:issue) %></th>
                <th style="width: 30%;"><%= TimeEntry.human_attribute_name(:description) %></th>
                <th></th>
              </tr>
            </thead>
            <tbody class="text-xs">
              <%
                total = 0
              %>
              <% @time_entries.each_with_index do |entry, i| %>
                <%
                  total += entry.total_logged_time_in_minutes
                %>
                <tr>
                  <td class="text-center">
                    <%= i %>
                  </td>
                  <td>
                    <%= l(entry.reference_date, format: :default) %>
                  </td>
                  <td>
                    <% if entry.project.present? %>
                      <%= entry.project.name %>
                    <% else %>
                      -
                    <% end %>
                  </td>
                  <td>
                    <%= entry.issue&.title %>
                  </td>
                  <td>

                    <%= simple_format(h(entry.description)) %>
                  </td>
                  <td>
                    <%= entry.total_logged_time_in_minutes %> min
                  </td>
                </tr>
              <% end %>
            </tbody>
          </table>
        </div>
      </div>
    <% else %>
      <%= render EmptyListComponent.new(message: t(".no_entries")) %>
    <% end %>
  </div>
<% end %>
